// Fill out your copyright notice in the Description page of Project Settings.


#include "AnimPlayer/Actions/ActionFactory.h"
#include "AnimPlayer/Actions/DissolveAction.h"
#include "AnimPlayer/Actions/ScaleAction.h"
#include "AnimPlayer/Actions/FadeAction.h"
#include "AnimPlayer/Actions/MarqueeAction.h"
#include "AnimPlayer/Actions/TranslateAction.h"


bool FActionFactory::Create(const FAnimActionInfo& ActionInfo, TSharedPtr<FActionBase>& ActionBase)
{
	switch (ActionInfo.Type)
	{
	case EAnimType::Scale:
		ActionBase = MakeShared<FScaleAction>();
		break;
	case EAnimType::Translate:
		ActionBase = MakeShared<FTranslateAction>();
		break;
	case EAnimType::Fade:
		ActionBase = MakeShared<FFadeAction>();
		break;
	case EAnimType::Dissolve:
		ActionBase = MakeShared<FDissolveAction>();
		break;
	case EAnimType::Marquee:
		ActionBase = MakeShared<FMarqueeAction>();
		break;
	default:
		break;
	}

	if (ActionBase.IsValid())
	{
		ActionBase->Layer = Cast<UMotionSubtitlesLayerBase>(ActionInfo.Layer.Get());
		ActionBase->Direction = ActionInfo.Direction;
		ActionBase->AnimTarget = ActionInfo.AnimTarget;
		ActionBase->ElementId = ActionInfo.ElementId;
		ActionBase->Curve = ActionInfo.Curve;
		ActionBase->StartOffset = ActionInfo.StartOffset;
		ActionBase->BeginTime = ((ActionInfo.AnimTarget == EAnimTarget::ContentElement) ? ActionInfo.StartOffset : 0);
		ActionBase->EndTime = ActionBase->BeginTime + ActionInfo.Duration;
		ActionBase->Duration = ActionInfo.Duration;
		return true;
	}
	return false;
}
